package com.yytek.am.util;

import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;

/**
 * js引擎规则工具
 */
public class AmJsRuleUtil {
    /**
     * js执行方法返回结果
     * @param es 执行字符串
     * @param replace 替换参数
     * @param param 参数值
     * @return
     * @throws ScriptException
     */
    public static Object scriptEngineManager(String es,String replace,String param) throws ScriptException {
        // 格式化字符串
        String result = es.replace(replace, param);
        // 创建JS对象
        ScriptEngineManager manager = new ScriptEngineManager();
        ScriptEngine js = manager.getEngineByName("js");
        return js.eval(result);
    }

}
